const md5 = require('md5')
const Admin = require("../models/Admin");
exports.addAdmin = async function (adminObj) {
    // 应该判断adminObj的各种属性是否合理，以及账号是否已存在

    // 密码MD5加密
    adminObj.loginpwd = md5(adminObj.loginpwd)
    const ins = await Admin.create(adminObj);
    return ins.toJSON();
};

exports.deleteAdmin = async function (adminId) {
    const result = await Admin.destroy({
        where: {
            id: adminId,
        },
    });
    return result;
};

exports.updateAdmin = async function (id, adminObj) {
    if (adminObj.loginpwd) {
        adminObj.loginpwd = md5(adminObj.loginpwd)
    }
    const result = await Admin.update(adminObj, {
        where: {
            id,
        },
    });
    return result;
};
